/**
 * Project Name:Micro-Services-Cross-Message
 * File Name   :Request.java
 * Package Name:com.micro.services.cross.message
 * Date:2015-9-6下午3:38:06
 * Copyright (c) 2015, http://my.oschina.net/httpssl All Rights Reserved.
 *
*/
/**
 *  {{Code Template Comments Files}}
 */

package com.micro.services.rpc;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;

import com.micro.services.common.enums.CodecType;
import com.micro.services.common.enums.ProtocolType;

/**
 * ClassName:Request <br/>
 * Function :TODO ADD FUNCTION. <br/>
 * Reason	:TODO ADD REASON. <br/>
 * Date     :2015-9-6 下午3:38:06 <br/>
 * @author  :http://my.oschina.net/httpssl
 * @email   :491835898@QQ.COM
 * @since   :JDK 1.7
 * @see 	 
 */
public class Request implements Serializable{
	private static final long serialVersionUID = 5450981231578035342L;
	
	private static final AtomicLong requestIdSeq = new AtomicLong();
	
	private byte[] targetInterfaceName;//目标SOA接口类名com.sstore.interfaces.IHello
	private byte[] methodName;
	private Object[] args = null;
	private byte[][] argTypes;
	private int timeout = 0;
	private long requestId;
	
	//默认为tcp
	private int protocolType = ProtocolType.tcp.ordinal();
	private int codecType = CodecType.jdk.ordinal();
	/**
	 * 如果走Tcp协议,半包粘包要自定义协议
	 */
	private byte[] data;
	private long data_length;
	
	/**
	 * 不带协议参数的构造函数
	 * @param targetInterfaceName 请求接口名称
	 * @param methodName 请求方法名称
	 * @param args 参数数组
	 * @param argTypes 参数类型数组 
	 * @param timeout 请求超时时间
	 */
	public Request(byte[] targetInterfaceName, byte[] methodName, Object[] args, byte[][] argTypes, int timeout){
		this(targetInterfaceName, methodName, args, argTypes, timeout,requestIdSeq.incrementAndGet());
	}
	public Request(byte[] targetInterfaceName, byte[] methodName, Object[] args, byte[][] argTypes, int timeout,
			long requestId) {
		super();
		this.targetInterfaceName = targetInterfaceName;
		this.methodName = methodName;
		this.args = args;
		this.argTypes = argTypes;
		this.timeout = timeout;
		this.requestId = requestId;
	}
	/**
	 * 带协议参数的构造函数
	 * @param targetInterfaceName 请求接口名称
	 * @param methodName 请求方法名称
	 * @param args 参数数组
	 * @param argTypes 参数类型数组 
	 * @param timeout 请求超时时间
	 * @param codecType 编解码方式 默认JDK
	 * @param protocolType 协议类型 @see com.sstore.core.enums.ProtocolType
	 */
	public Request(byte[] targetInterfaceName, byte[] methodName, Object[] args, byte[][] argTypes, int timeout,int codecType,int protocolType){
		this(targetInterfaceName, methodName, args, argTypes, timeout,requestIdSeq.incrementAndGet(),codecType,protocolType);
	}
	
	public Request(byte[] targetInterfaceName, byte[] methodName, Object[] args, byte[][] argTypes, int timeout,
			long requestId,int codecType,int protocolType) {
		super();
		this.targetInterfaceName = targetInterfaceName;
		this.methodName = methodName;
		this.args = args;
		this.argTypes = argTypes;
		this.timeout = timeout;
		this.requestId = requestId;
		this.setProtocolType(protocolType);
		this.codecType = codecType;
	}
	
	public int getProtocolType() {
		return protocolType;
	}
	public void setProtocolType(int protocolType) {
		this.protocolType = protocolType;
	}
	public byte[] getTargetInterfaceName() {
		return targetInterfaceName;
	}
	public void setTargetInterfaceName(byte[] targetInterfaceName) {
		this.targetInterfaceName = targetInterfaceName;
	}
	public byte[] getMethodName() {
		return methodName;
	}
	public void setMethodName(byte[] methodName) {
		this.methodName = methodName;
	}
	public Object[] getArgs() {
		return args;
	}
	public void setArgs(Object[] args) {
		this.args = args;
	}
	public byte[][] getArgTypes() {
		return argTypes;
	}
	public void setArgTypes(byte[][] argTypes) {
		this.argTypes = argTypes;
	}
	public int getTimeout() {
		return timeout;
	}
	public void setTimeout(int timeout) {
		this.timeout = timeout;
	}
	public long getRequestId() {
		return requestId;
	}
	public void setRequestId(long requestId) {
		this.requestId = requestId;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public static AtomicLong getRequestidseq() {
		return requestIdSeq;
	}
	
	public byte[] getData() {
		return data;
	}
	public void setData(byte[] data) {
		this.data = data;
	}
	public long getData_length() {
		return data_length;
	}
	public void setData_length(long data_length) {
		this.data_length = data_length;
	}
	public int getCodecType() {
		return codecType;
	}
	public void setCodecType(int codecType) {
		this.codecType = codecType;
	}
	
}